package com.briup.sms.web.controller;

import com.briup.sms.entity.Category;
import com.briup.sms.entity.extend.CategoryExtend;
import com.briup.sms.service.CategoryService;
import com.briup.sms.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author :xuyang
 * @DateTime:2023/12/27 10:48
 * @Version :v1.0.0
 * ClassName:CategoryController
 * Package  :com.briup.sms.web.controller
 * Description:TODO
 */
@RestController
@RequestMapping("/category")
@Api(tags = "分类管理")
public class CategoryController {

    @Autowired
    CategoryService service;

    //查询全部信息
    @ApiOperation("查询全部分类信息")
    @GetMapping("/findCategoryInfo")
    public Result findCategoryInfo() {
        List<CategoryExtend> list = service.findCategoryInfo();
        return Result.success(list);
    }

    @GetMapping("/findCategoryOneLevel")
    @ApiOperation("查询全部一级分类")
    public Result findCategoryOneLevel() {
        List<Category> list = service.findCategoryOneLevel();
        return Result.success(list);
    }

    @GetMapping("findCategoryByOneLevel/{id}")
    @ApiOperation("通过一级分类查二级分类")
    public Result findCategoryByOneLevel(@PathVariable Integer id) {
        List<CategoryExtend> list = service.findCategoryByOneLevel(id);
        return Result.success(list);
    }

    @PostMapping("/addCategory")
    @ApiOperation("添加分类信息")
    public Result addCategory(@RequestBody Category category) {
        service.addCategory(category);
        return Result.success();
    }

    @GetMapping("/findByName")
    @ApiOperation("根据分类名称检索")
    public Result findByName(String name) {
        List<Category> list = service.findByName(name);
        return Result.success(list);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除分类")
    public Result delete(@PathVariable Integer id) {
        service.delete(id);
        return Result.success();
    }

}
